﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Web.Framework.Search;
using CrmContacto.Contracts.Contracts.Search;
using System.Collections;

namespace Web.PuntoDeVenta.Code
{
    public class CustomerSearchObjectDataSourceProvider : IGridViewSearchObjectDataSource
    {
        //public WebServiceHelper WebServiceHelper { get; set; }

        public CustomerSearchParam SearchParam { get; set; }

        public CustomerSearchResult SearchResult { get; set; }

        public IList GetObjects()
        {
            return GetObjects(int.MaxValue, 0, string.Empty);
        }

        public IList GetObjects(int maximumRows, int startRowIndex)
        {
            return GetObjects(maximumRows, startRowIndex, string.Empty);
        }

        public IList GetObjects(string sortExpression)
        {
            return GetObjects(int.MaxValue, 0, sortExpression);
        }

        public int TotalNumberOfGetObjects()
        {
            return SearchResult.TotalDeResultados;
        }

        public IList GetObjects(int maximumRows, int startRowIndex, string sortExpression)
        {
            if (SearchParam != null)
            {
                //SearchParam.PageSize = maximumRows;
                SearchParam.PageSkip = startRowIndex;

                //SearchParam.SortingField = sortExpression;
                if (String.IsNullOrEmpty(SearchParam.SortingField))
                {
                    SearchParam.SortingField = "Id";
                    SearchParam.SortIsAsc = true;
                }

                SearchResult = WebServiceHelper.SearchForCustomerByNameOrDocOrEmail(SearchParam);
                return SearchResult.Resultados;
            }
            else
            {
                SearchResult = new CustomerSearchResult();
                return new List<int>(); //Devuelvo una lista vacía
            }
        }
    }
}